
tools_path <- Sys.getenv("tools_path")
data_path <- Sys.getenv("data_path")

dat <- paste(data_path, "/ref/b37/b37.1_Y.chr_length.txt", sep="")

win <- 200000

b37_1_y_chr_len <- read.table(dat, sep="\t")

win_num0 <- b37_1_y_chr_len[,2] %/% win

win_num1 <- b37_1_y_chr_len[,2] %% win

up_down_12 <- win_num1 / win >= .5

chr <- vector(mode="character")
star <- vector(mode="integer")
endd <- vector(mode="integer")
index <- 0
for (i in 1:length(win_num0)) {

	if (up_down_12[i]) {
		for (j in 1:win_num0[i]) {
			index = index + 1
			chr[index] <- b37_1_y_chr_len[i,1]
			star[index] <- win*(j-1)+1
			endd[index] <- win*j
		}
		index = index + 1
		chr[index] <- b37_1_y_chr_len[i,1]
		star[index] <- win*(j-1)+1
		endd[index] <- b37_1_y_chr_len[i,2]
	
	}else {
		for (j in 1:win_num0[i]-1) {
			index = index + 1
			chr[index] <- b37_1_y_chr_len[i,1]
			star[index] <- win*(j-1)+1
			endd[index] <- win*j
		}
		index = index + 1
		chr[index] <- b37_1_y_chr_len[i,1]
		star[index] <- win*(j-1)+1
		endd[index] <- b37_1_y_chr_len[i,2]
	}

}

genome_window <- data.frame(chr, star, endd)


